package lab03;

import com.mysql.cj.api.xdevapi.Collection;

import java.sql.*;

public class Testing {
    public static void main(String[] args) {
        Connection connection = null;
        Statement statement=null;
        ResultSet resultSet=null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/java_2017?" +
                    "serverTimezone=UTC&characterEncoding=utf-8", "root", "123456");
           statement=connection.createStatement();
           statement.executeUpdate("INSERT INTO t_students (stu_no,real_name,age,gender,department)" +
                   "VALUES ('12454','邱义城',18,0,'信息与工程学院')");
            statement.executeUpdate("INSERT INTO t_students (stu_no,real_name,age,gender,department)" +
                    "VALUES ('12454','何鑫',18,0,'信息与工程学院')");
            resultSet=statement.executeQuery("SELECT * FROM t_students");
            while (resultSet.next()){
                System.out.print("\t"+resultSet.getInt(1));
                System.out.print("\t"+resultSet.getString(2));
                System.out.print("\t"+resultSet.getString(3));
                System.out.print("\t"+resultSet.getInt(4));
                System.out.print("\t"+resultSet.getInt(5));
                System.out.println("\t"+resultSet.getString(6));
            }
            statement.executeUpdate("DELETE FROM t_students WHERE id=10" );
            statement.executeUpdate("UPDATE t_students set department='外语系'WHERE id=9");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
